package com.example.kx036;

import androidx.appcompat.app.AppCompatActivity;

import android.opengl.EGLExt;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;

/**
 * 图像切换器
 */
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageSwitcher is = findViewById(R.id.ImageSwitcher1);
        //设置淡出动画
        is.setOutAnimation(AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.fade_out));
        is.setInAnimation(AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.fade_in));

        is.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                //为图像切换器指定图像
                ImageView imageView = new ImageView(MainActivity.this);

                imageView.setImageResource(R.drawable.img01);

                return imageView;

            }
        });


        is.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ImageSwitcher is = (ImageSwitcher) view;
                is.setImageResource(R.drawable.img03);

            }
        });

    }
}